﻿var NodeID = UrlParm.parm('nodeid');

function setCheckAll(obj) {
    //alert(val);
    if (obj.checked) {
        CheckAll(obj.form);
    } else {
        UnSelectAll(obj.form);
    }
}



function getSelectVal() {//获取选择的值
    var selVal = '';
    $("[name='delid']").each(function() {
        if ($(this).attr('checked')) {
            if (selVal == '') {
                selVal = $(this).val();
            }
            else {
                selVal += ',' + $(this).val();
            }
        }
    });
    return selVal;
}

function doing(action, IndexID) {
    var returnValue;
    switch (action) {
        case 'restore':
            var returntext = $.ajax({ type: "POST", url: 'content_saveAdvance.aspx', data: 'ac=ajax_delete_restore&nodeid=' + NodeID + '&id=' + IndexID, async: false }).responseText;
            // alert(returntext); //调试错误信息
            var msg = eval("msg=" + returntext);
            if (msg.result == "1") {
                alert("恢复成功");
                window.location.reload(true);
            }
            else {
                alert(msg.msg); //出错信息
            }

            break;

        case 'destroy':
            var arr = showModalDialog("ConfirmDestroyContent.aspx?nodeid=" + NodeID, "color", "dialogWidth:300px;dialogHeight:106px;help:0;status:0;scroll:no");

            if (arr['v'] == "1") {
                var delattr = arr['delattr'];
                var delimg = arr['delimg'];
                var returntext = $.ajax({ type: "POST", url: 'content_saveAdvance.aspx', data: 'ac=ajax_delete_destroy&nodeid=' + NodeID + '&id=' + IndexID + '&delattr=' + delattr + '&delimg=' + delimg, async: false }).responseText;
                // alert(returntext); //调试错误信息
                var msg = eval("msg=" + returntext);
                if (msg.result == "1") {
                    alert("删除成功");
                    window.location.reload(true);
                }
                else {
                    alert(msg.msg); //出错信息
                }
            }
            break;
        case 'view':
            //alert("只个功能需要开发");
            var leftPos = (screen.availWidth - 800) / 2
            var topPos = (screen.availHeight - 600) / 2
            window.open('content_view.aspx?id=' + IndexID, '', 'width=800,height=600,scrollbars=yes,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);
            break;

    }
}


function rightMenu(pId, State, Type, Top, Pink, event) {
    var toolMenu = new WebFXMenu;

    toolMenu.add(new WebFXMenuItem('查看', 'javascript:doing("view","' + pId + '")', '查看文档内容'));
    toolMenu.add(new WebFXMenuItem('恢复', 'javascript:doing("restore","' + pId + '")', '恢复'));
    toolMenu.add(new WebFXMenuItem('永久删除', 'javascript:doing("destroy","' + pId + '")', '永久删除'));
    $("#menudata").html(toolMenu.toString());
    elo = window.event ? window.event.srcElement : event.target;
    toolMenu.left = event.clientX;
    toolMenu.top = event.clientY + document.body.scrollTop;
    toolMenu.show();
}

function going() {
    var selVal = getSelectVal();

    var val = $("#actionMap").val();

    switch (val) {
        case 'restore':
            if (selVal == '') { alert('请选择要操作的内容'); return false; }
            doing('restore', selVal);
            break;
        case 'destroy':
            if (selVal == '') { alert('请选择要操作的内容'); return false; }
            doing('destroy', selVal);
            break;
        case 'empty_recycle_bin':
            var arr = showModalDialog("publish/ConfirmDestroyContent.aspx?nodeid=" + NodeID, "color", "dialogWidth:300px;dialogHeight:206px;help:0;status:0;scroll:no");

            if (arr['v'] == "1") {
                var delattr = arr['delattr'];
                var delimg = arr['delimg'];
            i//f (confirm("确认清空回收站吗，该操作将不可恢复！")) {
            var returntext = $.ajax({ type: "POST", url: 'content_saveAdvance.aspx', data: 'ac=ajax_empty_recycle&nodeid=' + NodeID + '&delattr=' + delattr + '&delimg=' + delimg, async: false }).responseText;
                // alert(returntext); //调试错误信息
                var msg = eval("msg=" + returntext);
                if (msg.result == "1") {
                    alert("删除成功");
                    window.location.reload(true);
                }
                else {
                    alert(msg.msg); //出错信息
                }
                break;
            }

    }

}
